package com.windgo.controller.wx;

import com.windgo.bean.common.BaseRespVo;
import com.windgo.bean.common.BaseRespVo1;
import com.windgo.bean.wxVo.WxSearchVo;
import com.windgo.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 张林浩
 * @since 2022/10/14 17:03
 */
@RestController
@RequestMapping("wx/search")
public class UserSearchController {
    @Autowired
    SearchService searchService;

    /**
     * wx-search-index
     * @return
     */
    @GetMapping("index")
    public BaseRespVo index(){
        WxSearchVo wxSearchVo = searchService.searchIndex();
        return BaseRespVo.ok(wxSearchVo);
    }

    /**
     * wx-keyword-helper
     * @author zlh
     * @param keyword
     * @return
     */
    @GetMapping("helper")
    public BaseRespVo helper(String keyword){

        List<String> list = searchService.searchKeyWord(keyword);

        return BaseRespVo.ok(list);
    }

    /**
     * wx-clearhistory
     * @author zlh
     * @return
     */
    @PostMapping("clearhistory")
    public BaseRespVo cleanHistory(){

        int code = searchService.clearSearchHistory();

        if (code == 200){
            return BaseRespVo.ok(0,"成功");
        }else {
            return BaseRespVo.ok(600,"删除失败");
        }

    }



}
